Skip to content

Quotes in column names - postgresql #653

@trcorp1

Description

@trcorp1

Description

Quotes in column names seems to either be broken or not supported. I'm using an existing database and tables so I did not create the table though the interface

Steps to Reproduce the Problem

With the given table definition with quoted column

CREATE TABLE users (
    id integer NOT NULL,
    name text,
    "admin" boolean DEFAULT false
);

And the following model details

type User struct {
    ID int `json:"id" db:"id"`
	Name string `json:"name" db:"name"`
	Admin string `json:"admin" db:"admin"`
}

and alternatively with attempted quoted strings

type User struct {
    ID int `json:"id" db:"id"`
	Name string `json:"name" db:"name"`
	Admin string `json:"admin" db:"\"admin\""`
}

Expected Behavior

I expected to get the json results pulling from the table which I do receive if I quote out the admin field in the struct. The issue only appears with columns with quoted names

Actual Behavior

For the first model I get the following sql statement showing in buffalo dev

SELECT admin_users.admin, admin_users.name, admin_users.id FROM admin.users AS admin_users

which fails in pgadmin because the quotes are missing.
and then the following error:

{
    "error": "ERROR: column admin_users.admin does not exist (SQLSTATE 42703)"
}

With the alternative model the following sql statement is shown in buffalo dev

SELECT admin_users."admin", admin_users.name, admin_users.id FROM admin.users AS admin_users

which I can query successfully through pgadmin as the quotes are there.
But also generates the following error

{
    "error": "missing destination name admin in *[]models.User"
}

I of course may be trying to handle the quotes incorrectly so any guidance would be greatly appreciated. I was unable to locate any mention of how to handle this in the documentation. I also was not able to find any one else reporting the issue here or on slack channel suggest in the support section of the documentation

Info

rhel8, Pop 5.3.2 version through Buffalo v0.16.23

Metadata

Metadata

Assignees

No one assigned

    Labels

    s: triageSome tests need to be run to confirm the issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions