I am trying do execute an sql statement with a column name that contains "-". e.g. xx-yy
have tried 'xx-yy' [xx-yy]
all give either an error or print string 'xx-yy' instead of the contents
any suggestions?
Karl
~:psql indigo_history -U postgres -c "SELECT `rx-tx-RateWiFi` from device_history_1066129470 LIMIT 10";
-bash: rx-tx-RateWiFi: command not found
--
(10 rows)
~:psql indigo_history -U postgres -c "SELECT [rx-tx-RateWiFi] from device_history_1066129470 LIMIT 10";
ERROR: syntax error at or near "["
LINE 1: SELECT [rx-tx-RateWiFi] from device_history_1066129470 LIMI...
^
~:psql indigo_history -U postgres -c "SELECT 'rx-tx-RateWiFi' from device_history_1066129470 LIMIT 10";
?column?
----------------
rx-tx-RateWiFi
rx-tx-RateWiFi
rx-tx-RateWiFi
rx-tx-RateWiFi
rx-tx-RateWiFi
rx-tx-RateWiFi
rx-tx-RateWiFi
rx-tx-RateWiFi
rx-tx-RateWiFi
rx-tx-RateWiFi
(10 rows)
~:
~:psql indigo_history -U postgres -c "SELECT \"rx-tx-RateWiFi\" from device_history_1066129470 LIMIT 10";
ERROR: column "rx-tx-RateWiFi" does not exist
LINE 1: SELECT "rx-tx-RateWiFi" from device_history_1066129470 LIMI...
SELECT "rx-tx-RateWiFi" from device_history_1066129470 LIMIT 10
SELECT "rx-tx-RateWiFi" from device_history_1066129470 LIMIT 10;
ERROR: syntax error at or near "SELECT"
LINE 2: SELECT rx
^
indigo_history=#
SELECT rx-tx-RateWiFi from device_history_1066129470 LIMIT 10
SELECT rx-tx-RateWiFi from device_history_1066129470 LIMIT 10;
ERROR: column "rx" does not exist
LINE 1: SELECT rx-tx-RateWiFi from device_history_1066129470 LIMIT ...
^
There is a second kind of identifier: the delimited identifier or quoted identifier. It is formed by enclosing an arbitrary sequence of characters in double-quotes ("). A delimited identifier is always an identifier, never a key word. So "select" could be used to refer to a column or table named "select", whereas an unquoted select would be taken as a key word and would therefore provoke a parse error when used where a table or column name is expected.
Users browsing this forum: No registered users and 1 guest